package com.lyl.projectspringboot.dto.dtoMapper;

import com.lyl.projectspringboot.dto.UserDto;
import com.lyl.projectspringboot.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper(componentModel = "spring")
public interface UserMapper {

    //将User对象转换为UserDto对象
    @Mappings({
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "userName", target = "userName"),
            @Mapping(source = "userPhone", target = "userPhone"),
            @Mapping(source = "userSex", target = "userSex"),
            @Mapping(source = "userAddress", target = "userAddress"),
            @Mapping(source = "userEmail", target = "userEmail"),
            @Mapping(source = "userBirthday", target = "userBirthday")
    })
    public UserDto toDto(User user);

    //将UserDto对象转换为User对象
    @Mappings({
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "userName", target = "userName"),
            @Mapping(source = "userPhone", target = "userPhone"),
            @Mapping(source = "userSex", target = "userSex"),
            @Mapping(source = "userAddress", target = "userAddress"),
            @Mapping(source = "userEmail", target = "userEmail"),
            @Mapping(source = "userBirthday", target = "userBirthday")
    })
    public User toEntity(UserDto userDto);

    //将List<User>转换为List<UserDto>
    @Mappings({
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "userName", target = "userName"),
            @Mapping(source = "userPhone", target = "userPhone"),
            @Mapping(source = "userSex", target = "userSex"),
            @Mapping(source = "userAddress", target = "userAddress"),
            @Mapping(source = "userEmail", target = "userEmail"),
            @Mapping(source = "userBirthday", target = "userBirthday")
    })
    public List<UserDto> toDto(List<User> users);

    //将List<UserDto>转换为List<User>
    @Mappings({
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "userName", target = "userName"),
            @Mapping(source = "userPhone", target = "userPhone"),
            @Mapping(source = "userSex", target = "userSex"),
            @Mapping(source = "userAddress", target = "userAddress"),
            @Mapping(source = "userEmail", target = "userEmail"),
            @Mapping(source = "userBirthday", target = "userBirthday")
    })
    public List<User> toEntity(List<UserDto> userDtos);
}
